library(readstata13)
library(ggplot2)




###############
#Main Outcomes#
###############

data <- read.dta13("allresults.dta")
data$out<-as.factor(data$outcomes)
data$gr<-as.factor(data$groups)
data$above<-as.factor(data$above)

theme_base2 <- 
  theme_minimal(base_size=13)  + 
  theme(legend.position="none",  legend.key.size = unit(1,"line"),
        axis.text=element_text(size=13),axis.title.x=element_text(size=13),axis.title.y=element_text(size=13),
        plot.title = element_text(size=13, hjust= 0.5))


theme_base1 <- 
  theme_minimal(base_size=13)  + 
  theme(legend.position=c(0.9, .9),  legend.key.size = unit(1,"line"),
        axis.text=element_text(size=13),axis.title.x=element_text(size=13),axis.title.y=element_text(size=13),
        plot.title = element_text(size=13, hjust= 0.5))
data1<-data[data$groups==2 & data$outcomes<4, ] 

main<-ggplot(data1, aes(x=outcomes, y = estimate,color=above)) + coord_flip() +  
  geom_point(size = 2,position=position_dodge(0.2)) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.7,position=position_dodge(width=0.2))+
  #geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=1.6,position=position_dodge(width=0.2))+
  scale_color_manual(name="Priors",labels=c("Pessimistic", "Optimistic"),values=c("black","gray")) + 
  scale_y_continuous(limits = c(-1, 1))+ 
  scale_x_continuous(breaks = c(1,2,3),limits=c(0.5,3.5),labels = c("Attitudes", "Log Amount"  ,"Donate" ))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("Average Treatment Effect") + xlab("")+
  theme_base1 #+ ggtitle("Expellee Descendants") + geom_hline(yintercept=-1, colour="black", size=1.2)
main
ggsave("RecognitionResultsExpellees.pdf", width = 22, height = 18, units = "cm")  


data3<-data[data$groups==3 & data$outcomes<4, ] 


main<-ggplot(data3, aes(x=outcomes, y = estimate,color=above)) + coord_flip() +  
  geom_point(size = 2,position=position_dodge(0.2)) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.7,position=position_dodge(width=0.2))+
#  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=1.6,position=position_dodge(width=0.2))+
  scale_color_manual(name="Priors",labels=c("Pessimistic", "Optimistic"),values=c("black","gray")) + 
  scale_y_continuous(limits = c(-1, 1))+ 
  scale_x_continuous(breaks = c(1,2,3),limits=c(0.5,3.5),labels = c("Attitudes", "Log Amount"  ,"Donate" ))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("Average Treatment Effect") + xlab("")+
  theme_base1 #+ ggtitle("Difference:\nExpellee Descendants vs Non-Expellee Descendants") 
main
ggsave("RecognitionResultsDiff.pdf", width = 22, height = 18, units = "cm")  


############
#Mechanisms#
############



data1<-data[data$groups==2 & data$outcomes>3, ] 

main<-ggplot(data1, aes(x=outcomes, y = estimate,color=above)) + coord_flip() +  
  geom_point(size = 2,position=position_dodge(0.2)) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.7,position=position_dodge(width=0.2))+
  #geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=1.6,position=position_dodge(width=0.2))+
  scale_color_manual(name="Priors",labels=c("Pessimistic", "Optimistic"),values=c("black","gray")) + 
  scale_y_continuous(limits = c(-1, 1))+ 
  scale_x_continuous(breaks = c(4,5),limits=c(3.5,5.5),labels = c("Victimhood\nCompetition", "Recognition\nAbroad"))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("Average Treatment Effect") + xlab("")+ 
  theme_base1 #+  ggtitle("Expellee Descendants") #+ geom_hline(yintercept=-1, colour="black", size=1.2) 
main
ggsave("RecognitionMechExpellees.pdf", width = 22, height = 18, units = "cm")  






